<template>
	<el-container>
		<el-main id="print" style="padding: 0 0 20px">
			<TablePage
				:page-info="tablePageDefine"
				:input-data="inputData"
				:isDisabledHanlde="isDisabledHanlde"
				:isTabRadio="isTabRadio"
				:fromPageID="fromPageID"
				@dialogCloseRefreshEmit="$emit('dialogCloseRefreshEmit')"
			/>
		</el-main>
	</el-container>
</template>

<script lang="ts">
import FileIns from '/@/components/Linxyun/FileClient/FileClientApi/file_instance.js';
import TabPages from '../CustomCommon/tab_pages.js';
import TablePage from '/@/components/Linxyun/custom/TablePage/index.vue';
import { compare } from '/@/utils/extendMethods';
import {
	DialogDefineType,
	TablePageType,
	TabFieldType,
	ProcessType,
	CascadeCfgType,
	InputTypeArray,
	EInputType,
	ShowDefineType,
	DialogType,
	ButtonDefineType,
	ButtonStyleColor,
	ButtonStyleType,
	ButtonEventType,
	EventExcuteType,
	OperateColumnType,
	timestampType,
} from '/@/components/Linxyun/custom/DataStructs/commontype';
export default defineComponent({
	name: 'customTablePape',
	components: { TablePage },
	props: {
		pageid: { type: Number, default: 0 },
		inputData: { type: Object, default: () => ({}) },
		isDisabledHanlde: {
			type: Boolean,
			default: false,
		},
		isTabRadio: {
			type: Boolean,
			default: false,
		},
		fromPageID: {
			type: Number,
			default: -1,
		},
	},
	setup(props, ctx) {
		const tablePageDefine = reactive<TablePageType>({
			PageId: 0,
			PageName: '',
			TableName: '',
			BusinessID: '',
			EntCode: BASE_API.ENT_CODE || '',
			SubSysID: BASE_API.SubSysID || '',
			CheckBox: false,
			DataSourceOptID: '',
			MainParams: null,
			PopupSize: 0,
			ImportTemp: '',
			Extend: '',
			FieldDefines: [],
			TableShowDefines: [],
			AddShowDefines: [],
			EditShowDefines: [],
			FilterDefines: [],
			StatisticsDefines: [],
			DialogDefines: [],
			ButtonDefines: [],
			NeedPagination: true,
			InputData: null,
			NeedStatistics: false,
			ColButtonDefines: [],
			SearchEvent: {},
			OperateColumnDef: [],
		});

		onMounted(async () => {
			console.log('[Debug][CustomTab]Init, pageid: ', props.pageid, props.inputData);
			if (props.pageid == 0) {
				return;
			}
			const fileClient = await FileIns.instance();
			const tabPageItem = await TabPages.instance().getPage(props.pageid);
			console.log('tabPageItem', tabPageItem);
			if (tabPageItem) {
				if (tabPageItem._pageDefines && tabPageItem._pageDefines.pageDefine) {
					const pageinfo = tabPageItem._pageDefines.pageDefine;
					const businessID = pageinfo.BusinessID || '0';
					const checkBox = pageinfo.CheckBox === 'true' ? true : false;
					const dataSourceOptID = pageinfo.DataSourceOptID || '';
					const extend = pageinfo.DataSourceOptID || '';
					const mainParams = pageinfo.MainParams || '';
					const popupSize = pageinfo.PopupSize || 0;
					const importTemp = pageinfo.ImportTemp || '';
					const tabName = pageinfo.TabName || '';
					const title = pageinfo.Title || '';

					const needStatistics = pageinfo.TableConfig && pageinfo.TableConfig.count === true ? true : false;
					const statisticsField = pageinfo.TableConfig && pageinfo.TableConfig.countField ? pageinfo.TableConfig.countField : [];
					const onePageHide = pageinfo.TableConfig && pageinfo.TableConfig.onePageHide === true ? true : false;
					tablePageDefine.BusinessID = businessID;
					tablePageDefine.CheckBox = checkBox;
					tablePageDefine.DataSourceOptID = dataSourceOptID;
					tablePageDefine.Extend = extend;
					tablePageDefine.PopupSize = popupSize;
					tablePageDefine.ImportTemp = importTemp;
					tablePageDefine.PageId = props.pageid;
					tablePageDefine.TableName = tabName;
					tablePageDefine.MainParams = mainParams;
					tablePageDefine.BusinessID = businessID;
					tablePageDefine.PageName = title;
					tablePageDefine.NeedStatistics = needStatistics;
					tablePageDefine.StatisticsDefines = statisticsField;
					tablePageDefine.NeedPagination = onePageHide;
				}

				parseTableDefine(tabPageItem._pageDefines);

				// 表字段排序
				const tempFieldConfig = [...tablePageDefine.TableShowDefines!, ...tablePageDefine.OperateColumnDef];
				// console.log(tempFieldConfig);
				tablePageDefine.TableShowDefines = tempFieldConfig.sort(compare('ViewSeqID'));
				console.log('[Debug][CustomTab]Init, pageinfo: ', props.pageid, tabPageItem._pageDefines.TabName, tabPageItem);
			}
			console.log('[Debug][CustomTab]Init, input data: ', props.inputData);
		});

		const parseTableDefine = (_tableDefine: any) => {
			// console.log('parseTableDefine', _tableDefine);
			tablePageDefine.SearchEvent = _tableDefine.searchEvent;
			tablePageDefine.PageId = props.pageid;
			tablePageDefine.TableName = _tableDefine.TabName ? _tableDefine.TabName : '';
			if (_tableDefine.fields) {
				for (let i = 0; i < _tableDefine.fields.length; i++) {
					const addColWidth = _tableDefine.fields[i].AddColWidth ? _tableDefine.fields[i].AddColWidth : 0;
					const addProcessType = _tableDefine.fields[i].AddProcessType ? _tableDefine.fields[i].AddProcessType : ProcessType.Process;
					// console.log('addProcessType', addProcessType);
					const addSeqID = _tableDefine.fields[i].AddSeqID ? parseInt(_tableDefine.fields[i].AddSeqID) : 0;
					const ifCascadeShow = _tableDefine.fields[i].IfCascadeShow && _tableDefine.fields[i].IfCascadeShow === '1';
					const cascadeCfg: CascadeCfgType = { type: '', label: '', value: '' };
					if (ifCascadeShow && _tableDefine.fields[i].CascadeCfg) {
						// console.log('[Debug][CustomTablePage] onMounted, cascadeCfg: ', _tableDefine.fields[i].CascadeCfg, ' i: ', i);
						cascadeCfg.type = _tableDefine.fields[i].CascadeCfg.type || '';
						cascadeCfg.label = _tableDefine.fields[i].CascadeCfg.label || '';
						cascadeCfg.value = _tableDefine.fields[i].CascadeCfg.value || '';
					}

					let colWidth = 0;
					let filterWidth = 0;
					if (_tableDefine.fields[i].ColWidth) {
						colWidth = _tableDefine.fields[i].ColWidth[0] ? _tableDefine.fields[i].ColWidth[0] : 0;
						filterWidth = _tableDefine.fields[i].ColWidth[1] ? _tableDefine.fields[i].ColWidth[1] : 0;
					}

					const editColWidth = _tableDefine.fields[i].EditColWidth ? _tableDefine.fields[i].EditColWidth : 0;
					const editProcessType = _tableDefine.fields[i].EditProcessType ? _tableDefine.fields[i].EditProcessType : ProcessType.Process;
					const editSeqID = _tableDefine.fields[i].EditSeqID ? parseInt(_tableDefine.fields[i].EditSeqID) : 0;
					const fieldName = _tableDefine.fields[i].FieldName;
					const type = _tableDefine.fields[i].InputType || '0';
					// 	_tableDefine.fields[i].InputType && 0 + _tableDefine.fields[i].InputType > 0 && _tableDefine.fields[i].InputType < 12
					// 		? _tableDefine.fields[i].InputType
					// 		: '0';
					const inputType = EInputType[parseInt(type)];
					// console.log('inputType', inputType);
					const SequenceConfig: {
						prefix: string;
						time: timestampType;
						sequenceName: string;
					} = {
						prefix: '',
						time: timestampType.second,
						sequenceName: '',
					};
					if (parseInt(type) === EInputType['sequence']) {
						SequenceConfig.prefix = _tableDefine.fields[i].inputDefine.prefix;
						SequenceConfig.time = _tableDefine.fields[i].inputDefine.time;
						SequenceConfig.sequenceName = _tableDefine.fields[i].inputDefine.sequenceName;
						_tableDefine.fields[i].inputDefine = null;
					}

					const accuracy = _tableDefine.fields[i].accuracy
						? {
								open: _tableDefine.fields[i].accuracy.open || '0',
								digit: !isNaN(_tableDefine.fields[i].accuracy.digit) ? _tableDefine.fields[i].accuracy.digit : 2,
						  }
						: { open: '0', digit: 2 };

					// console.log('accuracy', accuracy);
					const dataStorageMode = _tableDefine.fields[i].dataStorageMode || 'file';
					// const depend = _tableDefine.fields[i].depend || [];
					const doptions = _tableDefine.fields[i].doptions || [];

					const inputDefine = _tableDefine.fields[i].inputDefine || null;

					const inputDataType = _tableDefine.fields[i].isParentInData || '0';
					// 如果是参数传入，没有配置传入字段值时，则默认用同字段名传入
					let inputFieldName = !_tableDefine.fields[i].inputFieldName
						? inputDataType === '1'
							? fieldName
							: ''
						: _tableDefine.fields[i].inputFieldName;
					const tipstext = _tableDefine.fields[i].tipstext || '';

					const InputCheck = _tableDefine.fields[i].InputCheck || {};
					InputCheck.isCheck = Number(InputCheck.isCheck) || 0;
					InputCheck.type = Number(InputCheck.type) || 0;
					InputCheck.value = InputCheck.value || '';

					const fieldDefine: TabFieldType = {
						PageID: props.pageid,
						FieldID: '',
						FieldName: fieldName,
						Label: _tableDefine.fields[i].label || '',
						InputType: inputType,
						Type: type,
						IsViewInTab: _tableDefine.fields[i].IsViewInTab || false,
						ColWidth: colWidth,
						InputDataType: Number(inputDataType),
						InputDataCfg: inputFieldName,
						IsFilter: _tableDefine.fields[i].IsFilter,
						FilterWidth: filterWidth,
						TipsText: tipstext,
						IsAddNeed: Number(addProcessType) === ProcessType.NotNeed ? false : true,
						AddColWidth: addColWidth,
						AddSeqID: addSeqID,
						AddProcessType: Number(addProcessType),
						IsEditNeed: Number(editProcessType) === ProcessType.NotNeed ? false : true,
						EditColWidth: editColWidth,
						EditSeqID: editSeqID,
						EditProcessType: Number(editProcessType),
						Accuracy: accuracy,
						IfCascadeShow: ifCascadeShow,
						CascadeCfg: cascadeCfg,
						NeedVerify: false,
						VerifyFunc: '',
						Extend: _tableDefine.fields[i].Extend || {},
						DataStorageMode: dataStorageMode,
						InputDefine: inputDefine,
						Doptions: doptions,
						// Depend: depend;
						InputCheck: InputCheck,
						DefaultValue: _tableDefine.fields[i].DefaultValue,
					};
					if (parseInt(type) === EInputType['sequence']) {
						fieldDefine.SequenceConfig = SequenceConfig;
					}
					if (parseInt(type) === EInputType['code-editor']) {
						fieldDefine.Language = _tableDefine.fields[i].Language;
					}

					tablePageDefine.FieldDefines!.push(fieldDefine);
					if (fieldDefine.IsFilter) {
						const filterDefine: ShowDefineType = { FieldName: fieldDefine.FieldName, FieldIndex: i };
						tablePageDefine.FilterDefines!.push(filterDefine);
					}
					if (fieldDefine.IsAddNeed) {
						const addShowDefine: ShowDefineType = { FieldName: fieldDefine.FieldName, FieldIndex: i };
						tablePageDefine.AddShowDefines!.push(addShowDefine);
					}
					if (fieldDefine.IsEditNeed) {
						const editShowDefine: ShowDefineType = { FieldName: fieldDefine.FieldName, FieldIndex: i };
						tablePageDefine.EditShowDefines!.push(editShowDefine);
					}
					if (fieldDefine.IsViewInTab) {
						const tabShowDefine: ShowDefineType = { FieldName: fieldDefine.FieldName, FieldIndex: i, ViewSeqID: _tableDefine.fields[i].ViewSeqID };
						tablePageDefine.TableShowDefines!.push(tabShowDefine);
					}
				}
			}
			parseTableBtnDefine(_tableDefine, tablePageDefine, ButtonStyleType.default);
		};

		const parseTableBtnDefine = (_tableDefine: any, tablePageDefine: TablePageType, buttonSyle: ButtonStyleType) => {
			// 查询栏按钮
			if (_tableDefine.searchEvent) {
				const searchBtnDef = createSimpleBtnDefine(_tableDefine.searchEvent, ButtonStyleColor.Primary, buttonSyle, 'query', false, {
					OpType: DialogType.query,
					Width: tablePageDefine.PopupSize,
					Height: 0,
					SubmitUrl: _tableDefine.searchEvent.event ? _tableDefine.searchEvent.event.url || '' : '',
					Title: _tableDefine.searchEvent.name,
					Content: '',
					InPutData: tablePageDefine.InputData,
					ExcuteData: {},
				} as DialogDefineType);
				if (searchBtnDef) {
					tablePageDefine.ButtonDefines?.push(searchBtnDef);
				}
			}

			if (_tableDefine.addEvent) {
				if (_tableDefine.addEvent?.event?.isBatch) {
					tablePageDefine.CheckBox = true;
				}
				console.log('_tableDefine.addEvent', _tableDefine.addEvent);
				const addBtnDef = createSimpleBtnDefine(_tableDefine.addEvent, ButtonStyleColor.Success, buttonSyle, 'query', false, {
					OpType: DialogType.add,
					Width: tablePageDefine.PopupSize,
					Height: 0,
					SubmitUrl: _tableDefine.addEvent.event ? _tableDefine.addEvent.event.url || '' : '',
					Title: _tableDefine.addEvent.name,
					Content: '',
					InPutData: tablePageDefine.InputData,
					ExcuteData: {},
					IsBatch: _tableDefine.addEvent.event?.isBatch || false,
					QueryRequiresBatchDataUrl: _tableDefine.addEvent.event?.queryRequiresBatchDataUrl || '',
					Params: _tableDefine.addEvent.event?.params || [],
					UpdateUrl: _tableDefine.addEvent.event.updateUrl || '',
				} as DialogDefineType);
				if (addBtnDef) {
					tablePageDefine.ButtonDefines?.push(addBtnDef);
				}
			}

			if (_tableDefine.exportEvent) {
				const exportBtnDef = createSimpleBtnDefine(_tableDefine.exportEvent, ButtonStyleColor.Info, buttonSyle, 'query', false, {
					OpType: DialogType.export,
					Width: tablePageDefine.PopupSize,
					Height: 0,
					SubmitUrl: _tableDefine.exportEvent.event ? _tableDefine.exportEvent.event.url || '' : '',
					Title: _tableDefine.exportEvent.name,
					Content: '',
					InPutData: tablePageDefine.InputData,
					ExcuteData: {},
				} as DialogDefineType);
				if (exportBtnDef) {
					tablePageDefine.ButtonDefines?.push(exportBtnDef);
				}
			}

			// 有下载导入就要有下载模版按钮
			if (_tableDefine.importEvent) {
				console.log('_tableDefine.importEvent', _tableDefine.importEvent);
				const colData = _tableDefine.importEvent.colData || [];
				const startRow = _tableDefine.importEvent.startRow || 1;
				const name = _tableDefine.importEvent.name || '导入';
				_tableDefine.importEvent['event'] = {
					url: _tableDefine.importEvent.event,
				};
				console.log('importEvent', _tableDefine.importEvent);
				const importBtnDef = createSimpleBtnDefine(_tableDefine.importEvent, ButtonStyleColor.Primary, buttonSyle, 'query', false, {
					OpType: DialogType.import,
					Width: tablePageDefine.PopupSize,
					Height: 0,
					SubmitUrl: _tableDefine.importEvent.event || '',
					Title: name,
					Content: '',
					InPutData: { InputData: tablePageDefine.InputData, ColData: colData, StartRow: startRow },
					ExcuteData: {},
				} as DialogDefineType);
				if (importBtnDef) {
					tablePageDefine.ButtonDefines?.push(importBtnDef);
				}
				if (_tableDefine.ImportTemp) {
					const importEvent = { event: { url: _tableDefine.ImportTemp }, type: 'down', name: '下载导入模版' };
					const importDownBtnDef = createSimpleBtnDefine(importEvent, ButtonStyleColor.Primary, buttonSyle, 'query', false, {
						OpType: DialogType.down,
						Width: tablePageDefine.PopupSize,
						Height: 0,
						SubmitUrl: _tableDefine.ImportTemp,
						Title: '下载导入模版',
						Content: '',
						InPutData: tablePageDefine.InputData,
						ExcuteData: {},
					} as DialogDefineType);
					if (importDownBtnDef) {
						tablePageDefine.ButtonDefines?.push(importDownBtnDef);
					}
				}
			}

			if (_tableDefine.pageprintEvent) {
				const printBtnDef = createSimpleBtnDefine(_tableDefine.pageprintEvent, ButtonStyleColor.Success, buttonSyle, 'query', false, {
					OpType: DialogType.print,
					Width: tablePageDefine.PopupSize,
					Height: 0,
					SubmitUrl: _tableDefine.pageprintEvent.event ? _tableDefine.pageprintEvent.event.url || '' : '',
					Title: _tableDefine.pageprintEvent.name,
					Content: '',
					InPutData: tablePageDefine.InputData,
					ExcuteData: {},
				} as DialogDefineType);
				if (printBtnDef) {
					tablePageDefine.ButtonDefines?.push(printBtnDef);
				}
			}

			if (_tableDefine.temprintEvent) {
				const tplPrintBtnDef = createSimpleBtnDefine(_tableDefine.temprintEvent, ButtonStyleColor.Info, buttonSyle, 'query', false, {
					OpType: DialogType.tplprint,
					Width: tablePageDefine.PopupSize,
					Height: 0,
					SubmitUrl: _tableDefine.temprintEvent.event ? _tableDefine.temprintEvent.event.url || '' : '',
					Title: _tableDefine.temprintEvent.name,
					Content: '',
					InPutData: tablePageDefine.InputData,
					ExcuteData: {},
				} as DialogDefineType);
				if (tplPrintBtnDef) {
					tablePageDefine.ButtonDefines?.push(tplPrintBtnDef);
				}
			}

			if (_tableDefine.optCols && _tableDefine.optCols.length > 0) {
				tablePageDefine.OperateColumnDef = [];
				for (let col = 0; col < _tableDefine.optCols.length; col++) {
					// 操作列配置
					const operateColumn: OperateColumnType = {
						ColWidth: _tableDefine.optCols[col].ColWidth,
						ColumnName: _tableDefine.optCols[col].ColumnName,
						ViewSeqID: _tableDefine.optCols[col].ViewSeqID,
						Index: col,
						FixedCol: _tableDefine.optCols[col].FixedCol,
					};
					tablePageDefine.OperateColumnDef.push(operateColumn);
					tablePageDefine.ColButtonDefines!.push({ ...operateColumn, btns: [] });
					if (_tableDefine.optCols[col].buttonDefines && _tableDefine.optCols[col].buttonDefines.length > 0) {
						for (let colbtnidx = 0; colbtnidx < _tableDefine.optCols[col].buttonDefines.length; colbtnidx++) {
							const btnEventInfo = _tableDefine.optCols[col].buttonDefines[colbtnidx];
							let btnColor = ButtonStyleColor.Primary;
							if (btnEventInfo.type == 1) {
								btnColor = ButtonStyleColor.Danger;
								btnEventInfo.type = 'delete';
								btnEventInfo.needComfirm = true;
							} else if (btnEventInfo.type == 2) {
								btnColor = ButtonStyleColor.Info;
								btnEventInfo.type = 'detail';
							} else if (btnEventInfo.type == 99) {
								btnColor = btnEventInfo.btnColor || ButtonStyleColor.Success;
								btnEventInfo.type = 'customize';
							} else if (btnEventInfo.type == 0) {
								btnEventInfo.type = 'edit';
							} else if (btnEventInfo.type == 3) {
								btnEventInfo.type = 'print';
							} else if (btnEventInfo.type == 4) {
								btnEventInfo.type = 'tplprint';
							}

							const needCfm = (btnEventInfo.needComfirm && (btnEventInfo.needComfirm == 'true' || btnEventInfo.needComfirm == true)) || false;

							// 修改
							if (btnEventInfo.type == 'edit') {
								const colsBtnDef = createSimpleBtnDefine(btnEventInfo, btnColor, buttonSyle, 'optcol', needCfm, {
									OpType: DialogType.edit,
									Width: tablePageDefine.PopupSize,
									Height: 0,
									SubmitUrl: btnEventInfo.event ? btnEventInfo.event.url || '' : '',
									Title: btnEventInfo.name,
									Content: '',
									InPutData: tablePageDefine.InputData,
									ExcuteData: {},
								} as DialogDefineType);
								if (colsBtnDef) {
									tablePageDefine.ColButtonDefines![col].btns.push(colsBtnDef);
								}
							} else if (btnEventInfo.type == 'delete') {
								const colsBtnDef = createSimpleBtnDefine(btnEventInfo, btnColor, buttonSyle, 'optcol', needCfm, {
									OpType: DialogType.delete,
									Width: tablePageDefine.PopupSize,
									Height: 0,
									SubmitUrl: btnEventInfo.event ? btnEventInfo.event.url || '' : '',
									Title: btnEventInfo.name,
									Content: '',
									InPutData: tablePageDefine.InputData,
									ExcuteData: {},
								} as DialogDefineType);
								if (colsBtnDef) {
									tablePageDefine.ColButtonDefines![col].btns.push(colsBtnDef);
								}
							} else if (btnEventInfo.type == 'detail') {
								const ExcuteData = {
									isGroup: btnEventInfo.isGroup,
									groups: btnEventInfo.groups,
								};
								const colsBtnDef = createSimpleBtnDefine(btnEventInfo, btnColor, buttonSyle, 'optcol', needCfm, {
									OpType: DialogType.detail,
									Width: tablePageDefine.PopupSize,
									Height: 0,
									SubmitUrl: btnEventInfo.event ? btnEventInfo.event.url || '' : '',
									Title: btnEventInfo.name,
									Content: '',
									InPutData: tablePageDefine.InputData,
									ExcuteData: ExcuteData,
								} as DialogDefineType);
								if (colsBtnDef) {
									tablePageDefine.ColButtonDefines![col].btns.push(colsBtnDef);
								}
							} else if (btnEventInfo.type === 'print') {
								console.log('print', btnEventInfo);
								const colsBtnDef = createSimpleBtnDefine(btnEventInfo, btnColor, buttonSyle, 'optcol', needCfm, {
									OpType: DialogType.print,
									Width: tablePageDefine.PopupSize,
									Height: 0,
									SubmitUrl: btnEventInfo.event ? btnEventInfo.event.url || '' : '',
									Title: btnEventInfo.name,
									Content: '',
									InPutData: tablePageDefine.InputData,
									ExcuteData: {},
								} as DialogDefineType);
								if (colsBtnDef) {
									tablePageDefine.ColButtonDefines![col].btns.push(colsBtnDef);
								}
							} else if (btnEventInfo.type === 'tplprint') {
								const colsBtnDef = createSimpleBtnDefine(btnEventInfo, btnColor, buttonSyle, 'optcol', needCfm, {
									OpType: DialogType.tplprint,
									Width: tablePageDefine.PopupSize,
									Height: 0,
									SubmitUrl: btnEventInfo.event ? btnEventInfo.event.url || '' : '',
									Title: btnEventInfo.name,
									Content: '',
									InPutData: tablePageDefine.InputData,
									ExcuteData: {},
								} as DialogDefineType);
								if (colsBtnDef) {
									tablePageDefine.ColButtonDefines![col].btns.push(colsBtnDef);
								}
							} else if (btnEventInfo.type == 'customize') {
								const colsBtnDef = createSimpleBtnDefine(btnEventInfo, btnColor, buttonSyle, 'optcol', needCfm, {
									OpType: DialogType.customize,
									Width: btnEventInfo.width,
									Height: 0,
									SubmitUrl: btnEventInfo.event ? btnEventInfo.event.url || '' : '',
									Title: btnEventInfo.name,
									Content: '',
									InPutData: tablePageDefine.InputData,
									ExcuteData: {},
								} as DialogDefineType);
								if (colsBtnDef) {
									tablePageDefine.ColButtonDefines![col].btns.push(colsBtnDef);
								}
							}
						}
					}
					// 操作栏自定义按钮
				}
				// 搜索栏自定义
				if (_tableDefine.otherEvents && _tableDefine.otherEvents.length > 0) {
					for (let otherBtnIdx = 0; otherBtnIdx < _tableDefine.otherEvents.length; otherBtnIdx++) {
						const btnEventInfo = _tableDefine.otherEvents[otherBtnIdx];

						if (btnEventInfo.ltype === EventExcuteType.Interface && !tablePageDefine.CheckBox) {
							tablePageDefine.CheckBox = true;
						}
						btnEventInfo.type = 'customize';
						let btnColor = ButtonStyleColor.Primary;
						console.log('搜索栏自定义', btnEventInfo, tablePageDefine);
						const needCfm = (btnEventInfo.needComfirm && (btnEventInfo.needComfirm == 'true' || btnEventInfo.needComfirm == true)) || false;
						const colsBtnDef = createSimpleBtnDefine(btnEventInfo, btnColor, buttonSyle, 'query', needCfm, {
							OpType: DialogType.customize,
							Width: tablePageDefine.PopupSize,
							Height: 0,
							SubmitUrl: btnEventInfo.cb || '',
							Title: btnEventInfo.name,
							Content: '',
							InPutData: tablePageDefine.InputData,
							ExcuteData: {},
						} as DialogDefineType);
						console.log('colsBtnDef', colsBtnDef);
						if (colsBtnDef) {
							tablePageDefine.ButtonDefines?.push(colsBtnDef);
						}
					}
				}
			}
			// 如 add update Print Tplprint
			function createSimpleBtnDefine(
				_eventInfo: any,
				styleColor: ButtonStyleColor,
				styleType: ButtonStyleType,
				showLocal: string,
				needComfirm: boolean,
				dialogDefine: DialogDefineType
			) {
				// 添加按钮默使用Add弹窗
				if (_eventInfo) {
					const btnType: DialogType = DialogType[_eventInfo.type];
					if (btnType >= DialogType.confirm && btnType <= DialogType.down) {
						const btnName = _eventInfo.name || '';
						let url;
						let opType;
						if (_eventInfo.type === 'customize') {
							// console.log('_eventInfo', _eventInfo);
							url = _eventInfo.cb;
							opType = _eventInfo.ltype;
						} else {
							opType = EventExcuteType.Inner;
							url = _eventInfo.event && _eventInfo.event.url ? _eventInfo.event.url : null;
						}

						const btnStyle = _eventInfo.event && _eventInfo.event.btnStyle ? _eventInfo.event.btnStyle : styleType; // 如果有配置样式就用配置的。
						const params =
							_eventInfo.event?.params?.map((item: any) => {
								const arr = ['Vuex.', 'LocalStorage.', '$'];
								let inputDataType = 0;
								for (let index = 0; index < arr.length; index++) {
									console.log('index', arr[index]);
									const index2 = item.value.indexOf(arr[index]);
									if (index2 === 0) {
										// 从vuex中获取
										if (index === 0) {
											inputDataType = 1;
											break;
											// 从本地缓存中获取
										} else if (index === 1) {
											inputDataType = 3;
											break;
											// 表达式
										} else if (index === 2) {
											inputDataType = 4;
											break;
										}
									} else {
										if (props.inputData && props.inputData[item.value]) {
											// 从路由参数中获取
											inputDataType = 1;
											break;
										} else {
											// 固定参数
											inputDataType = 2;
											break;
										}
									}
								}
								return {
									Type: item.type,
									ParamKey: item.name,
									ParamVal: item.value,
									InputDataType: inputDataType,
								};
							}) || null;
						const eventDefine: ButtonEventType = {
							OpType: opType,
							TargetVal: url,
							DialogDefine: dialogDefine,
							Params: params, // TODO 处理参数
						};
						const buttonDefine: ButtonDefineType = {
							ButtonKey: '',
							ShowLocal: showLocal,
							Title: btnName,
							SubmitUrl: url,
							ShowCtrl: _eventInfo.showCtrField,
							NeedComfirm: needComfirm,
							ConfirmEventDefine: null,
							BeforeEventDefine: null,
							AfterEvnetDefine: null,
							EventDefine: eventDefine,
							BtnStyleColor: styleColor,
							BtnStyleType: btnStyle,
						};

						return buttonDefine;
					} else {
						// 数据不合法
						return null;
					}
				}
			}
			// console.log('tablePageDefine', tablePageDefine);
		};
		return {
			tablePageDefine,
		};
	},
});
</script>
